package com.jk.lesson3;

import com.jk.lesson2.Apple;
import com.jk.lesson2.Predicate;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * Created by Auser on 2016/11/9.
 */
public class FunctionTest {
    public static <T, R> List<R> map(List<T> list, Function<T, R> function){
        List<R> res = new ArrayList<>();
        for(T s : list)
            res.add(function.apply(s));
        return res;
    }

    public static void main(String...args){
        List<Integer> l = map(Arrays.asList("admin",  "tom", "action"), s -> s.length());
        System.out .println(l.toString());
        Comparator<Apple> c1 = (o1, o2) -> o1.getWeight().compareTo(o2.getWeight());
        System.out.println();

        Predicate<Integer> p = integer ->  l.add(integer);
        Consumer<String> c = s -> l.add(123);

        int a = 123;
        Consumer<String> s = s1 -> System.out.println(a);
    }
}
